const state = {
  isConnected: false,
  message: '',
  reconnectError: false,
  reconnectCount: ''
};
const mutations = {
  SOCKET_ONOPEN(state, event) {

    state.isConnected = true
  },
  SOCKET_ONCLOSE(state, event) {
    state.isConnected = false
  },
  SOCKET_ONERROR(state, event) {
    console.error(state, event)
  },
  // default handler called for all methods
  SOCKET_ONMESSAGE(state, message) {
    state.message = message
  },
  // mutations for reconnect methods
  SOCKET_RECONNECT(state, count) {
    console.info(state, count);
    state.reconnectCount = count
  },
  SOCKET_RECONNECT_ERROR(state) {
    state.reconnectError = true;
  },
};
const actions = {
  sendMessage: function (context, message) {
    Vue.prototype.$socket.send(message)
  }
};


export default {
  namespaced: true,
  state,
  mutations,
  actions
}
